Skip to content

Read u32 values only from SHORT and LONG entries, as C++ does - #21

Merged
copybara-service[bot] merged 1 commit into
google:masterfrom
kunpai:u32-short-or-long-only
Nov 5, 2026
Merged

copybara-service[bot] merged 1 commit into
google:masterfrom
kunpai:u32-short-or-long-only

Conversation

@kunpai

@kunpai kunpai commented Nov 4, 2026 •

Copy link
Copy Markdown
Contributor

Read u32 values only from SHORT and LONG entries, as C++ does

Problem

TiffDirectory::Get for a uint32_t (C++, Rust) reads a tag's value as a number: the orientation, the image sizes and offsets, and the Exif and GPS pointers all go through it. C++ reads only SHORT and LONG entries. The port's get_u32_vec, which get_u32 calls, also reads entries of type IFD (13), although its doc comment says Short and Long. For example:

C++ Rust
a CR3 whose CMT1 Orientation, 8, has type IFD orientation 1 orientation 8
a DNG whose ExifIFD entry has type IFD kOk; no Exif fields (ISO 0, no date) kOk; ISO 200, date "2020:01:02 03:04:05"
a DNG whose IFD0 Orientation, 6, has type IFD kFail kOk; orientation 6, preview 1024×768

The CR3's orientation is the same from Cr3GetPreviewData and Cr3GetOrientation. In the last row, an Orientation that does not read fails the directory in C++; the port does the same, but its read succeeds.

Question

Which behaviour do we want: C++'s or the Rust port's? Specifically, for a value stored in an entry of type IFD, should reading it as a uint32_t fail (like the C++ library), or give the value as if it were a LONG (like the Rust port)?

This PR implements C++'s behaviour.

Fix

get_u32_vec reads SHORT and LONG entries only, as its doc comment says and as C++'s Get does, and its second match drops the IFD arm it no longer reaches:

-            TiffType::Long | TiffType::Ifd => 4,
+            TiffType::Long => 4,

The examples above then match C++. Replayed before and after:

C++ Rust main Rust patched
CR3, Orientation of type IFD orientation 1 orientation 8 orientation 1
DNG, ExifIFD of type IFD no Exif fields ISO 200, date no Exif fields
DNG, IFD0 Orientation of type IFD kFail kOk kFail

Of the campaigns' inputs, one CR3 differs from C++ in its orientation on main and none with this PR; no other input changes. The port's tests pass unchanged (44 + 174).

Notes for review:

@1c3t3a 1c3t3a left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes we want to do the same as C++, thanks a lot for the PR Kunal!

@copybara-service
copybara-service Bot merged commit 8b7533b into google:master Nov 5, 2026
9 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants